<template>
  <a-card :bordered="false">

    <div>
      <div class="title">人员基本信息</div>
      <a-form-model layout="vertical" ref="ruleForm1" :rules="rules" :model="model">
        <z-form-item :datas="fieldArr" :rules="rules" :form="model" :gutter="72" @change="getChange">
          <!--//自定义头像上传-->
          <template slot="slots-avatar">
            <j-image-upload bizPath="scott/pic" v-model="model.avatar" />
          </template>
        </z-form-item>
      </a-form-model>
    </div>
    <div>
      <div class="title">人员入所信息</div>
      <a-form-model layout="vertical" ref="ruleForm2" :rules="rules" :model="model">
        <z-form-item :datas="fieldArr1" :rules="rules" :form="model" :gutter="72" @change="getChange">
          <template slot="slots-decisionOrgan">
            <j-select-depart v-model="model.decisionOrgan" :multi="true"></j-select-depart>
          </template>
        </z-form-item>
      </a-form-model>
    </div>
    <div>
      <div class="title">人员出所信息</div>
      <a-form-model layout="vertical" ref="ruleForm3" :rules="rules" :model="model">
        <a-row :gutter="72">
          <a-col :span="6">
            <a-form-model-item label="是否已出所" prop="isLeftOffice">
              <j-dict-select-tag
                v-model="model.isLeftOffice"
                dictCode="dict_yn"
                placeholder="请选择是否出所"
                style="min-width: 100px"
                @change="handleInput"
              />
            </a-form-model-item>
          </a-col>
          <template v-if="ChuSuo">
            <a-col :span="6" v-if="">
              <a-form-model-item label="实际出所日期">
                <a-date-picker
                  v-model="model.actualDepartureTime"
                  format="YYYY-MM-DD"
                  style="width: 100%"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="出所原因" prop="reasonGoOut">
                <j-dict-select-tag
                  v-model="model.reasonGoOut"
                  dictCode="ChuSuoY"
                  placeholder="请选择出所原因"
                  style="min-width: 100px"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="出所原因" prop="departure">
                <a-input
                  v-model="model.departure"
                  placeholder="请输入出所去向"
                  style="min-width: 100px"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="接收民警" prop="receivePoliceName">
                <a-input
                  v-model="model.receivePoliceName"
                  placeholder="请输入接收民警"
                  style="min-width: 100px"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="接收家属" prop="receiveFamilyName">
                <a-input
                  v-model="model.receiveFamilyName"
                  placeholder="请输入接收家属"
                  style="min-width: 100px"
                />
              </a-form-model-item>
            </a-col>
            <a-col :span="6">
              <a-form-model-item label="接收家属联系方式" prop="receiveFamilyPhone">
                <a-input
                  v-model="model.receiveFamilyPhone"
                  placeholder="请输入接收家属联系方式"
                  style="min-width: 100px"
                />
              </a-form-model-item>
            </a-col>
          </template>
        </a-row>
      </a-form-model>
      <a-button type="primary" @click="onSubmit">确定</a-button>
      <a-button style="margin-left: 20px" @click="onSubmitF">取消</a-button>
    </div>
  </a-card>

</template>

<script>
import { queryDepartByArea } from '@/api/api'
import {DataDetails, editExceptionData} from "@api/sjsk/receiveCase";
export default {
  props: ['current', 'controlPersonType', 'value'],
  data() {
    return {
      ChuSuo:true,
      model: {
        socialDrugKeywordLists:[]
      },
      model1:{},
      plainOptions:[
        { label: '海洛因', value: '1' },
        { label: '鸦片', value: '2' },
        { label: '大麻', value: '3' },
        { label: '吗啡', value: '4' },
        { label: '冰毒', value: '5' },
        { label: '冰毒片剂', value: '6' },
        { label: '咖啡因', value: '7' },
        { label: '安钠咖', value: '8' },
        { label: '氯胺酮', value: '9' },
        { label: '安眠酮', value: '10' },
        { label: '杜冷丁', value: '11' },
        { label: '可卡因', value: '12' },
        { label: '罂粟壳', value: '13' },
        { label: '摇头丸', value: '14' },
        { label: '其他苯丙胺类毒品', value: '15' },
        { label: '埃托啡', value: '16' },
        { label: '其他毒品', value: '17' },
      ],
      fieldArr: [
        {label: '姓名', prop: 'realName', tagType: 'input', span: 6,disabled: true},
        {label: '别名/绰号', prop: 'nickName', tagType: 'input', span: 6,disabled: true},
        {label: '性别', prop: 'sex', tagType: 'dict-select', dictCode:'sex', span: 6,disabled: true},
        {label: '民族', prop: 'nation', tagType: 'dict-select', dictCode:'nation', span: 6,disabled: true},
        {label: '出生年月', prop: '', tagType: 'date-picker', format: 'YYYY-MM-DD', span: 6,disabled: true},
        {label: '身高（cm）', prop: 'height', tagType: 'input', span: 6,disabled: true},
        {label: '国籍', prop: 'country', tagType: 'dict-select', dictCode:'country', span: 6,disabled: true},
        {label: '婚姻状况', prop: 'marriage', tagType: 'dict-select', dictCode:'marriage', span: 6,disabled: true},
        {label: '证件类型', prop: 'certificateType', tagType: 'dict-select', dictCode:'other_certificate_type', span: 6,disabled: true},
        {label: '证件号码', prop: 'identityCard', tagType: 'input', span: 6},
        {label: '文化程度', prop: 'education', tagType: 'dict-select', dictCode:'degreeEducation', span: 6,disabled: true},
        {label: '职业', prop: 'workUnit', tagType: 'input', span: 6,disabled: true},
        {label: '户籍地', prop: 'householdTown', tagType: 'input', span: 12,disabled: true},
        {label: '户籍地详址', prop: 'householdAddress', tagType: 'input', span: 6,disabled: true},
        // {label: '户籍地派出所', prop: 'householdPoliceStation', tagType: 'input',disabled: true, span: 6},
        {label: '户籍地派出所', prop: 'householdPoliceStation', tagType: 'input',span: 6,disabled: true},
        {label: '现居住地', prop: 'currentTown', tagType: 'input', span: 12,disabled: true},
        {label: '现居住地详址', prop: 'currentAddress', tagType: 'input', span: 6,disabled: true},
        {label: '居住地派出所', prop: 'currentPoliceStation', tagType: 'input',span: 6,disabled: true},
        {label: '照片', prop: 'avatar'},
      ],
      fieldArr1:[
        {label: '戒毒所名称', prop: 'durgRehabilitatioName', tagType: 'dict-select', dictCode:'risk_category', span: 6,disabled: true},
        {label: '初次吸毒日期', prop: 'firstDrugTime', tagType: 'date-picker', format: 'YYYY-MM-DD', span: 6},
        {label: '既往戒毒次数', prop: 'previousDurgNum', tagType: 'input', span: 6},
        {label: '是否复吸', prop: 'isReAbsorption', tagType: 'dict-select', dictCode:'dict_yn', span: 6},
        {label: '入所原因', prop: 'reasonsAdmission', tagType: 'input', span: 6},
        {label: '入所日期', prop: 'admissionTime', tagType: 'date-picker', format: 'YYYY-MM-DD', span: 6},
        {label: '起始日期', prop: 'enterStartTime', tagType: 'date-picker', format: 'YYYY-MM-DD', span: 6},
        {label: '截至日期', prop: 'enterEndTime', tagType: 'date-picker', format: 'YYYY-MM-DD', span: 6},
        {label: '戒毒期限', prop: 'durgRehabilitationPeriod', tagType: 'dict-select', dictCode:'JieDuTime', span: 6},
        {label: '决定机关', prop: 'decisionOrgan',span: 6},
        {label: '吸毒方式', prop: 'drugWays', tagType: 'dict-multi-tag', dictCode:'drug_ways', type:'checkbox'},
        {label: '吸毒类型', prop: 'drugType',tagType: 'dict-multi-tag', dictCode:'XiDiType', type:'checkbox'},
      ],
      socialDrugOptions: [
        { keyword: '自愿戒毒', value: 3 },
        { keyword: '社区戒毒', value: 1 },
        { keyword: '社区康复', value: 2 },
        { keyword: '强制隔离戒毒', value: 4 },
        { keyword: '无', value: 5 },
      ],
      prisonsTypeOptions: [],
      prisonsNameOptions: [
        {key: '1', title: '测试'},
        {key: '2', title: '测2试'},
      ],
      rules: {
        // 头像上传
        avatar: [{ required: true, message: '请上传头像', trigger: 'change' },],
        realName: [ { required: true, message: '请输入', trigger: 'change' }, ],
        sjskType: [ { required: true, message: '请选择', trigger: 'change' }, ],
        sjskStartDate: [ { required: true, message: '请选择', trigger: 'change' }, ],
        sjskEndDate: [ { required: true, message: '请选择', trigger: 'change' }, ],
        sex: [ { required: true, message: '请选择', trigger: 'change' }, ],
        birthday: [ { required: true, message: '请选择', trigger: 'change' }, ],
        // education: [ { required: true, message: '请选择', trigger: 'change' }, ],
        height: [ { required: true, message: '请输入', trigger: 'change' }, ],
        nation: [ { required: true, message: '请选择', trigger: 'change' }, ],
        country: [ { required: true, message: '请选择', trigger: 'change' }, ],
        identityCard: [ { required: true, message: '请输入', trigger: 'change' }, ],
        personType: [ { required: true, message: '请选择', trigger: 'change' }, ],
        education: [ { required: true, message: '请选择', trigger: 'change' }, ],
        phone: [ { required: true, message: '请输入', trigger: 'change' }, ],
        houseLevels: [ { required: true, message: '请选择', trigger: 'change' }, ],
        householdAddress: [ { required: true, message: '请输入', trigger: 'change' }, ],
        householdPoliceStation: [ { required: true, message: '请输入', trigger: 'change' }, ],
        currentLevels: [ { required: true, message: '请选择', trigger: 'change' }, ],
        currentAddress: [ { required: true, message: '请输入', trigger: 'change' }, ],
        currentPoliceStation: [ { required: true, message: '请选择居住地地区', trigger: 'change' }, ],
        marriage: [ { required: true, message: '请选择', trigger: 'change' }, ],
        workSituation: [ { required: true, message: '请选择', trigger: 'change' }, ],
        healthStatus: [ { required: true, message: '请选择', trigger: 'change' }, ],
        isJoinMedicineTreatment: [ { required: true, message: '请选择', trigger: 'change' }, ],
        isIntoRecurePlace: [ { required: true, message: '请选择', trigger: 'change' }, ],
        firstDrugDate: [ { required: true, message: '请选择', trigger: 'change' }, ],
        riskCategory: [ { required: true, message: '请选择', trigger: 'change' }, ],
        isResorption: [ { required: true, message: '请选择', trigger: 'change' }, ],
        abstinenceDrugTimes: [ { required: true, message: '请输入', trigger: 'change' }, ],
        controlLevel: [ { required: true, message: '请选择', trigger: 'change' }, ],
        outDate: [ { required: true, message: '请选择', trigger: 'change' }, ],
        drugWays: [ { required: true, message: '请选择', trigger: 'change' }, ],
        drugType: [ { required: true, message: '请选择', trigger: 'change' }, ],
        socialDrugKeywordLists: [
          { required: true, type:'array', message: '请选择', trigger: 'change' },
          { validator: this.socialDrugLists }
        ]
      }
    }
  },
  computed: {
    getValue() {
      let value = this.value ? this.value : {}
      return value
    }
  },
  mounted() {
    this.initTabTypes()
    this.receiveCaseLook()
  },
  watch:{
    $route (data){
      console.log(data)
    }
  },
  methods: {

    onSubmit(){
      console.log(this.model)
      this.$refs.ruleForm1.validate(valid => {
        if(valid){
          editExceptionData(this.model).then(ser => {
            console.log(ser)
            if(ser.success){
              this.$message.success('编辑成功')
              localStorage.setItem('Yc','1')
              this.$router.push({
                path:'/record/list',
                query:{
                  Yc:'1'
                }
              })
            } else {
              this.$message.info('请检查数据')
            }
          }).catch(err => {})
        }
      })
    },
    onSubmitF(){
      this.$router.push({
        path:'/record/list',
        query:{
          Yc:'1'
        }
      })
    },
    receiveCaseLook() {
      if (this.$route.query.id) {
        DataDetails({id: this.$route.query.id}).then(ser => {
          if (ser.success) {
            this.model = ser.result
            if(this.model.isLeftOffice === '1'){
              this.ChuSuo = true
            } else {
              this.ChuSuo = false
            }
          }
        }).catch(err => {
          console.log(err)
        })
      } else {
        this.$message.error('非法进入！');
        history.go(-1)
      }

    },
    handleInput(val){
      console.log(val,'66')
      if(val === '1'){
        this.ChuSuo = true
      } else {
        this.ChuSuo = false
      }
    },
    getChange(prop, value) {
      if(prop==='riskCategory') {
        this.$set(this.model, 'controlLevel', value)
        this.$refs['ruleForm'].validateField('controlLevel')
      }
      if(prop==='houseLevels') {
        let lastData = value.length>0?value[value.length-1]:''
        let flastData = value.length>0?value[value.length-2]:''
        this.$set(this.model, 'houseLevel', value.toString())
        this.$set(this.model, 'houseDepartmentId', lastData)
        if(value && value.length===5) this.getQueryDepartByArea(flastData, 'houseLevel')
      }
      if(prop==='currentLevels') {
        let lastData = value.length>0?value[value.length-1]:''
        let flastData = value.length>0?value[value.length-2]:''
        this.$set(this.model, 'currentLevel', value.toString())
        this.$set(this.model, 'currentDepartmentId', lastData)
        if(value && value.length===5) this.getQueryDepartByArea(flastData, 'currentLevel')
      }
    },
    // 通过执行社区筛选派出所信息
    getQueryDepartByArea(code, field) {
      queryDepartByArea({type: 2, code})
        .then(res => {
          if (res.success) {
            const { result } = res
            if(result && Object.keys(result).length>0 && result.departName) {
              let departName = result.departName
              if(field==='houseLevel')this.$set(this.model, 'householdPoliceStation', departName)
              if(field==='currentLevel')this.$set(this.model, 'currentPoliceStation', departName)
            }
          } else {
            this.$message.warn(res.message)
          }
        })
        .catch(e => {
          this.$message.warn('请求失败！')
        })
    },
    // 初始化字典项
    initTabTypes() {
      this.$initDictOptions('prisons_type').then((res) => {
        if (res.success) {
          this.prisonsTypeOptions = res.result.map(item=> {
            return {
              title: item.label,
              key: Number(item.value)
            }
          })
        }
      })
    },
  }
}
</script>

<style scoped lang="less">
.title{
  width: 100%;
  border-bottom: 1px solid #E9E9E9;
  margin-bottom: 25px;
  padding-bottom: 15px;
  font-size: 18px;
  font-weight: 600
}
.slots-checkbox{
  :deep(&.ant-checkbox-group) {
    .ant-checkbox-wrapper {
      display: flex;
      align-items: center;
      margin-bottom: 16px;
      margin-left: 0;
      .label {
        width: 200px;
        display: inline-block;
      }
      .ant-calendar-picker {
        width: 240px;
        flex: 0 0 240px;
      }
      .ant-select {
        flex: 0 0 200px;
      }
    }
  }
}
</style>
